home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac 1993 September
/
September 93.iso
/
Archives
/
Utilities
/
Disk & File
/
Disk
/
Icons
/
Icon Disposer
/
IconDisposerCDEV.c
< prev
next >
Wrap
Text File
|
1993-06-16
|
8KB
|
333 lines
#define SystemSevenOrLater 1
#include <Quickdraw.h>
#include <Files.h>
#include <Memory.h>
#include <OSUtils.h>
#include <TextEdit.h>
#include <Devices.h>
#include <Dialogs.h>
#include <Packages.h>
#include <GestaltEqu.h>
#include <Resources.h>
#include <Controls.h>
#define kOnMask (0x01)
#define kOnClear (0xFF - kOnMask)
#define kCDMask (0x02)
#define kCDClear (0xFF - kCDMask)
#define kNetVolMask (0x04)
#define kNetVolClear (0xFF - kNetVolMask)
#define kFloppyMask (0x08)
#define kFloppyClear (0xFF - kFloppyMask)
#define kLocalMask (0x10)
#define kLocalClear (0xFF - kLocalMask)
#define kOnRadio 2
#define kOffRadio 3
#define kCDCheck 5
#define kNetVolCheck 6
#define kFloppyCheck 7
#define kLocalCheck 8
#define kCheckFrameItem 9
#define kStatusItem 10
#define kStatFrameItem 11
struct GlobalVar {
unsigned char flags;
short volumes[50];
};
typedef struct GlobalVar GlobalVar;
typedef GlobalVar *GlobalVarPtr;
typedef GlobalVar **GlobalVarHandle;
void ReevaluateVolumes(GlobalVarHandle globals);
pascal long IconDisposerCDEV(short message, short item, short numItems,
short CPanelID, EventRecord *theEvent, Handle cdevStorage,
DialogPtr CPDialog)
{
#pragma unused (CPanelID)
GlobalVar **globals = nil;
ControlHandle onButton;
ControlHandle offButton;
ControlHandle aControlHandle;
ControlHandle cdHandle;
ControlHandle netVolHandle;
ControlHandle floppyHandle;
ControlHandle localHandle;
ControlHandle statusHandle;
short type;
OSErr theErr = noErr;
Rect rect;
Handle aHandle;
short itemHit = item - numItems;
short partID;
short initControlValue;
short value;
unsigned char maskVal = 0;
unsigned char clearVal = 0;
unsigned char maskValue = 0;
unsigned char flagCopy = 0;
if (message == macDev)
return(1);
else
if (cdevStorage)
{
GetDItem(CPDialog, kOnRadio, &type, (Handle *) &onButton, &rect);
GetDItem(CPDialog, kOffRadio, &type, (Handle *) &offButton, &rect);
GetDItem(CPDialog, kCDCheck, &type, (Handle *) &cdHandle, &rect);
GetDItem(CPDialog, kNetVolCheck, &type, (Handle *) &netVolHandle, &rect);
GetDItem(CPDialog, kFloppyCheck, &type, (Handle *) &floppyHandle, &rect);
GetDItem(CPDialog, kLocalCheck, &type, (Handle *) &localHandle, &rect);
GetDItem(CPDialog, kStatusItem, &type, (Handle *) &statusHandle, &rect);
theErr = Gestalt('byeb', (long *) &globals);
if (theErr == gestaltUnknownErr)
return(cdevGenErr);
if (theErr == gestaltUndefSelectorErr)
{
globals = nil;
aHandle = Get1IndResource('glob', 1);
if (aHandle)
{
flagCopy = *(unsigned char *)(*aHandle);
ReleaseResource(aHandle);
}
else
flagCopy = 0;
}
else
flagCopy = (*globals)->flags;
switch (message) {
case initDev:
if (kOnMask & flagCopy)
{
SetCtlValue(onButton, 1);
SetCtlValue(offButton, 0);
initControlValue = 0;
}
else
{
SetCtlValue(onButton, 0);
SetCtlValue(offButton, 1);
initControlValue = 255;
}
HiliteControl(cdHandle, initControlValue);
HiliteControl(netVolHandle, initControlValue);
HiliteControl(floppyHandle, initControlValue);
HiliteControl(localHandle, initControlValue);
if (kCDMask & flagCopy)
SetCtlValue(cdHandle, 1);
else
SetCtlValue(cdHandle, 0);
if (kNetVolMask & flagCopy)
SetCtlValue(netVolHandle, 1);
else
SetCtlValue(netVolHandle, 0);
if (kFloppyMask & flagCopy)
SetCtlValue(floppyHandle, 1);
else
SetCtlValue(floppyHandle, 0);
if (kLocalMask & flagCopy)
SetCtlValue(localHandle, 1);
else
SetCtlValue(localHandle, 0);
break;
case closeDev:
if (!globals)
{
flagCopy = 0;
value = GetCtlValue(onButton);
if (value)
flagCopy |= kOnMask;
else
flagCopy &= kOnClear;
value = GetCtlValue(cdHandle);
if (value)
flagCopy |= kCDMask;
else
flagCopy &= kCDClear;
value = GetCtlValue(netVolHandle);
if (value)
flagCopy |= kNetVolMask;
else
flagCopy &= kNetVolClear;
value = GetCtlValue(floppyHandle);
if (value)
flagCopy |= kFloppyMask;
else
flagCopy &= kFloppyClear;
value = GetCtlValue(localHandle);
if (value)
flagCopy |= kLocalMask;
else
flagCopy &= kLocalClear;
}
aHandle = (Handle) Get1IndResource('glob', 1);
if (aHandle)
{
RmveResource(aHandle);
DisposeHandle((Handle) aHandle);
}
aHandle = NewHandle(1);
if (aHandle)
{
*(unsigned char *)(*aHandle) = flagCopy;
AddResource(aHandle, 'glob', 1, "\p");
ChangedResource(aHandle);
if (ResError())
break;
WriteResource(aHandle);
ReleaseResource(aHandle);
}
if (globals)
ReevaluateVolumes(globals);
break;
case hitDev:
GlobalToLocal(&theEvent->where);
partID = FindControl(theEvent->where, (WindowPtr) CPDialog, &aControlHandle);
switch (itemHit) {
case kOnRadio:
if (!(kOnMask & flagCopy))
{
SetCtlValue(offButton, 0);
if (globals)
(*globals)->flags |= kOnMask;
}
initControlValue = 0;
case kOffRadio:
if (itemHit == kOffRadio)
{
if (kOnMask & flagCopy)
{
SetCtlValue(onButton, 0);
if (globals)
(*globals)->flags &= kOnClear;
}
initControlValue = 255;
}
SetCtlValue(aControlHandle, 1);
HiliteControl(cdHandle, initControlValue);
HiliteControl(netVolHandle, initControlValue);
HiliteControl(floppyHandle, initControlValue);
HiliteControl(localHandle, initControlValue);
break;
}
if (partID)
partID = TrackControl(aControlHandle, theEvent->where,
nil);
if (partID)
{
switch (itemHit) {
case kCDCheck:
maskVal = kCDMask;
clearVal = kCDClear;
break;
case kNetVolCheck:
maskVal = kNetVolMask;
clearVal = kNetVolClear;
break;
case kFloppyCheck:
maskVal = kFloppyMask;
clearVal = kFloppyClear;
break;
case kLocalCheck:
maskVal = kLocalMask;
clearVal = kLocalClear;
break;
}
if (maskVal & flagCopy)
{
SetCtlValue(aControlHandle, 0);
if (globals)
(*globals)->flags &= clearVal;
}
else
{
SetCtlValue(aControlHandle, 1);
if (globals)
(*globals)->flags |= maskVal;
}
}
break;
case updateDev:
case activDev:
DrawControls((WindowPtr) CPDialog);
GetDItem(CPDialog, kStatFrameItem, &type,
(Handle *) &aControlHandle, &rect);
FrameRect(&rect);
if (globals == nil)
SetIText((Handle) statusHandle,
"\pThis Control Panel was not installed. Please reboot.");
GetDItem(CPDialog, kCheckFrameItem, &type,
(Handle *) &aControlHandle, &rect);
FrameRect(&rect);
break;
}
return ((long) cdevStorage);
}
return (0);
}
void ReevaluateVolumes(GlobalVarHandle globals)
{
VCB* vcbQueue = *((QHdrPtr *) 0x0358);
short vRefNum;
short newValue;
Debugger();
while (vcbQueue)
{
vRefNum = vcbQueue->vcbVRefNum;
if (((vcbQueue->vcbFSID > 0) && (kNetVolMask & (*globals)->flags)) ||
(((vcbQueue->vcbDrvNum == 1) || (vcbQueue->vcbDrvNum == 2)) &&
((*globals)->flags & kFloppyMask)) ||
((vcbQueue->vcbAtrb & 0x80) && ((*globals)->flags & kCDMask)) ||
((*globals)->flags & kLocalMask))
newValue = 1;
else
newValue = 0;
*(short *)((*(Ptr *)globals) + (-vRefNum)) = newValue;
vcbQueue =(VCB *) vcbQueue->qLink;
}
}